/**
 * 
 * @param user 
 * @param key 
 */
function findValueByKey(user:IUsers,key:string){
    type k1 = keyof IUsers  //返回结果k1 =   id | name
    // return user[key]  //报错：key是string，但是key具体什么结果无法判断。没办法作为对象属性
    // return user[key as keyof IUsers]
    return (user as any)[key]
}
interface IUsers {
    id:number,
    name:string
}
const myuser:IUsers = {
    id:1,name:"xiaowang"
}

findValueByKey(myuser,"id")

type k2 = keyof IUsers   //k2 = "id | name"
type k3 = keyof IUsers[] //k3 = "length | toString() | push | pop"


/**
 * 通用方法，不管传递数据格式。默认获取值
 * @param user 
 * @param key 
 * @returns 
 */
function findValueByKey2<T extends IUsers,K extends keyof IUsers>(user:T,key:K){
    return user[key]
}

export {}
